package com.sailor.dingding.service;


import com.sailor.dingding.entity.DingdingRequest;
import com.sailor.dingding.utils.DingdingSendMsgUtil;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @description: 钉钉服务
 * @author: wwz
 * @date: 2023/02/03
 */
@Data
public class DingdingService {

    @Autowired
    private DingdingSendMsgUtil dingdingSendMsgUtil;

    /**
     * 钉钉应用 appKey
     */
    private String appKey;

    /**
     * 钉钉应用 appSecret
     */
    private String appSecret;

    /**
     * 钉钉应用 agentId
     */
    private Long agentId;


    public DingdingService() {
    }

    public DingdingService(String appKey, String appSecret, Long agentId) {
        this.appKey = appKey;
        this.appSecret = appSecret;
        this.agentId = agentId;
    }

    /**
     * 通过手机号发送消息
     *
     * @param content
     * @param phone
     * @throws Exception
     */
    public void sendOAMsgByPhone(DingdingRequest dingdingRequest) throws Exception {
        dingdingSendMsgUtil.sendOAMsgByPhone(dingdingRequest.getContent(), dingdingRequest.getPhone(), dingdingRequest.getUrl(), agentId, appKey, appSecret);
    }
}
